//
//  AYMMKV.m
//  SuiXin
//
//  Created by boWen on 2023/10/17.
//

#import "AYMMKV.h"
#import <MMKV/MMKV.h>

@implementation AYMMKV

#pragma mark - set存储

+ (BOOL)setString:(NSString *)value forKey:(NSString *)key {
    return [[MMKV defaultMMKV] setString:value forKey:key];
}

+ (BOOL)setData:(NSData *)value forKey:(NSString *)key  {
    return [[MMKV defaultMMKV] setObject:value forKey:key];
}

+ (BOOL)setBool:(BOOL)value forKey:(NSString *)key  {
    return [[MMKV defaultMMKV] setBool:value forKey:key];
}

+ (BOOL)setFloat:(float)value forKey:(NSString *)key  {
    return [[MMKV defaultMMKV] setFloat:value forKey:key];
}

+ (BOOL)setInt64:(uint64_t)value forKey:(NSString *)key {
    return [[MMKV defaultMMKV] setUInt64:value forKey:key];
}

+ (BOOL)setUInt32:(uint32_t)value forKey:(NSString *)key {
    return [[MMKV defaultMMKV] setUInt32:value forKey:key];
}


#pragma mark - get取值


+ (nullable NSString *)getStringForKey:(NSString *)key {
    return [[MMKV defaultMMKV] getStringForKey:key];
}

+ (nullable NSString *)getStringForKey:(NSString *)key defaultValue:(nullable NSString *)defaultValue {
    return [[MMKV defaultMMKV] getStringForKey:key defaultValue:defaultValue];
}

+ (nullable NSData *)getDataForKey:(NSString *)key {
    return [[MMKV defaultMMKV] getDataForKey:key defaultValue:nil];
}
+ (nullable NSData *)getDataForKey:(NSString *)key defaultValue:(nullable NSData *)defaultValue {
    return [[MMKV defaultMMKV] getDataForKey:key defaultValue:defaultValue hasValue:nil];
}

+ (float)getFloatForKey:(NSString *)key {
    return [[MMKV defaultMMKV] getFloatForKey:key];
}

+ (float)getFloatForKey:(NSString *)key defaultValue:(float)defaultValue {
    return [[MMKV defaultMMKV] getFloatForKey:key defaultValue:defaultValue];
}

+ (int32_t)getInt32ForKey:(NSString *)key defaultValue:(int32_t)defaultValue {
    return [[MMKV defaultMMKV] getInt32ForKey:key defaultValue:defaultValue];
}

+ (int32_t)getInt32ForKey:(NSString *)key {
    return [[MMKV defaultMMKV] getInt32ForKey:key];
}

+ (int64_t)getInt64ForKey:(NSString *)key {
    return [[MMKV defaultMMKV] getInt64ForKey:key defaultValue:0 hasValue:nil];
}
+ (int64_t)getInt64ForKey:(NSString *)key defaultValue:(int64_t)defaultValue {
    return [[MMKV defaultMMKV] getInt64ForKey:key defaultValue:defaultValue hasValue:nil];
}


+ (BOOL)getBoolForKey:(NSString *)key {
    return [[MMKV defaultMMKV] getBoolForKey:key];
}

+ (BOOL)getBoolForKey:(NSString *)key defaultValue:(BOOL)defaultValue {
    return [[MMKV defaultMMKV] getBoolForKey:key defaultValue:defaultValue];
}

#pragma mark - 移除某个key

+ (void)removeValueForKey:(NSString *)key {
    return [[MMKV defaultMMKV] removeValueForKey:key];
}

#pragma mark - 删除多个

+ (void)removeValuesForKeys:(NSArray *)arrKeys {
    return [[MMKV defaultMMKV] removeValuesForKeys:arrKeys];
}


#pragma mark - 删除所有键值，删除磁盘文件

+ (void)close{
    return [[MMKV defaultMMKV] close];
}

// 删除缓存，不删除磁盘文件
+ (void)clearMemoryCache {
    return [[MMKV defaultMMKV] clearMemoryCache];
}

//是否存在某个key
+ (BOOL)containsKey:(NSString *)key {
    return [[MMKV defaultMMKV] containsKey:key];
}


@end
